package com.atguigu.gmall.controller;

import com.atguigu.gmall.entity.BaseBrand;
import com.atguigu.gmall.result.RetVal;
import com.atguigu.gmall.search.Product;
import com.atguigu.gmall.search.SearchParam;
import com.atguigu.gmall.search.SearchResponseVo;
import com.atguigu.gmall.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;
    @Autowired
    private SearchService searchService;

    //创建索引
    @GetMapping("createIndex")
    public RetVal createIndex(){
        elasticsearchRestTemplate.createIndex(Product.class);
        elasticsearchRestTemplate.putMapping(Product.class);
        return RetVal.ok();
    }
   /* //上架
    @GetMapping("onSale/{skuId}")
    public RetVal onSale(@PathVariable Long skuId){
        searchService.onSale(skuId);
        return RetVal.ok();
    }
    //下架
    @GetMapping("offSale/{skuId}")
    public RetVal offSale(@PathVariable Long skuId){
        searchService.offSale(skuId);
        return RetVal.ok();
    }*/
    //4.商品的热度排名
    @GetMapping("incrHotScore/{skuId}")
    public RetVal incrHotScore(@PathVariable Long skuId){
        searchService.incrHotScore(skuId);
        return RetVal.ok();
    }

    //响应数据
    @PostMapping("/findProductBySearchParam")
    public RetVal findProductByKeyWord(@RequestBody SearchParam searchParam){
        SearchResponseVo searchResponseVo = searchService.findProductByKeyWord(searchParam);
        return RetVal.ok(searchResponseVo);
    }

}
